import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
        'upToken',
		'upUserInfo'
    ]),
	handlerChoose(){
		this.agree = !this.agree
	},
	toLogin(){
		uni.navigateTo({
			url: '/pages/publics/login'
		})
	},
	nextStep(){
		if(!this.formData.email){
			this.$toast.msg('请输入邮箱', {
			    icon: 1
			})
			return false
		}
		if(!this.formData.code){
			this.$toast.msg('请输入验证码', {
			    icon: 1
			})
			return false
		}
		this.step = 2
	},
	//用户协议
	toUserAgreement(){
		uni.navigateTo({
			url: '/pages/publics/userAgreement'
		})
	},
	privacyAgreement(){
		uni.navigateTo({
			url: '/pages/publics/privacyAgreement'
		})
	},
	
    submitForm() {
        let that = this
        if (that.loading) {
            that.$toast.msg('请求中...', {
                icon: 1
            })
            return false
        }
        that.loading = true
    		that.$httpRequest.request({
    		    that: that,
    		    url: 'h5/resetPasswordEmail',
    		    params: that.formData,
    		    success: res => {
    		        that.loading = false
    		        if (res.code === that.$httpConfig.SUCCESS_CODE) {
    					
    		            that.$toast.alert({
    		            	content: res.message,
    		            	callback: result => {
    		            		uni.navigateTo({
    		            			url:'/pages/publics/emailLogin'
    		            		})
    		            	}
    		            })
    		        } else {
    		            that.$toast.alert({
    		                content: res.message,
    		                callback: result => {
    
    		                }
    		            })
    		        }
    		    }
    		})
    
    },
	getCode() {
	    let that = this
		
	    if (that.loading) {
	        that.$toast.msg('请求中...', {
	            icon: 1
	        })
	        return false
	    }
	    that.loading = true
		
	    that.$httpRequest.request({
	        that: that,
	        url: 'h5/sendMail',
	        params: {
	            email: that.formData.email,
				type:2,//1 注册，2 忘记密码
	        },
	        success: res => {
	            that.loading = false
	
				
	            if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.getTxt = 60
					that.loopNum()
	            }else{
					that.$toast.msg(res.message, {
					  icon: 1
					})
				}
	        }
	    })
	},
	loopNum() {
		let that = this
	    that.intervalObj = setInterval(() => {
			that.num--
			if (that.num <= 0) {
				clearInterval(that.intervalObj)
				that.num = 60
				that.getTxt = "获取"
			}
	    }, 1000)
		
	},

}
